package com.base.maintain;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author yanjiaqiang
 * @date 2010-12-31
 * @version $Id: RegexMatcher.java 7 2011-07-15 04:24:04Z JiaqiangYan@gmail.com $
 */
public class RegexMatcher implements StringMatcher {

	private Pattern regexPattern;

	public RegexMatcher(String regex) {
		this(Pattern.compile(regex));
	}

	public RegexMatcher(Pattern regexPattern) {
		super();
		this.regexPattern = regexPattern;
	}

	@Override
	public List<String> match(String str) {
		Matcher matcher = regexPattern.matcher(str);
		List<String> list = new ArrayList<String>();
		while (matcher.find()) {
			list.add(matcher.group());
		}
		return list;
	}

}
